// pages/compare/compare.js
let datas = require('../../data/racquets-data');
var Head = [];
var Wilson = [];
var Babolat = [];
var Yonex = []

Page({
  data: {
    multiArray01: [
      ['品牌', 'HEAD', 'WILSON', 'BABOLAT', 'YONEX'],
      ['系列'],
    ],
    multiIndex01: [0,0],
    multiArray02: [
      ['品牌', 'HEAD', 'WILSON', 'BABOLAT', 'YONEX'],
      ['系列'],
    ],
    multiIndex02: [0, 0],
    selectleft: {},
    selectright: {},
    avatar: '/images/tab/white.png',
  },

  bindMultiPickerChange01: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({ 
      multiIndex01: e.detail.value
    })
    console.log(e.detail)
    //console.log('修改的列为', e.detail.column, '，值为', e.detail.value);

  },
  bindMultiPickerColumnChange01: function(e) {
    console.log('修改的列为', e.detail.column, '，值为', e.detail.value);
    var multiArray01 = this.data.multiArray01,
        multiIndex01 = this.data.multiIndex01
    multiIndex01[0] = e.detail.value;//根据不同第一列的index，分别渲染不同的第二列数据
    // switch (e.detail.column) {
    //   case 0:
        switch (multiIndex01[0]) {
          case 0:multiArray01[1] = ['系列'];break;
          case 1:multiArray01[1] = Head;break;
          case 2:multiArray01[1] = Wilson;break;
          case 3:multiArray01[1] = Babolat;break;
          case 4:multiArray01[1] = Yonex;break;
        }
//    }
    this.setData({
      multiArray01,
      multiIndex01
    });
  
    for (var i = 0; i < datas.racquets_data.length; i++) {
      if (
        //multiArray01[0][multiIndex01[0]] == datas.racquets_data[i].brand &&
        multiArray01[1][multiIndex01[1]] == datas.racquets_data[i].name
      ) {
        var select01 = datas.racquets_data[i];//选中的球拍
        //console.log(select01);
        break;
      } else {
        select01 = {};
      }
    }
    this.setData({
      selectleft: select01,
    });
    console.log(multiArray01[0][multiIndex01[0]]);
    console.log(multiArray01[1][multiIndex01[1]]);
  },


  bindMultiPickerChange02: function(e) {
    this.setData({
      multiIndex: e.detail.value
    })
  },
  bindMultiPickerColumnChange02: function(e) {
    var multiArray02 = this.data.multiArray02,
      multiIndex02 = this.data.multiIndex02
    console.log(e.detail)
    multiIndex02[e.detail.column] = e.detail.value;
    // switch (e.detail.column) {
    //   case 0:
        switch (multiIndex02[0]) {
          case 0:
            multiArray02[1] = ['系列'];
            break;
          case 1:
            multiArray02[1] = Head;
            break;
          case 2:
            multiArray02[1] = Wilson;
            break;
          case 3:
            multiArray02[1] = Babolat;
            break;
          case 4:
            multiArray02[1] = Yonex;
            break;
        }
    // }
    //console.log(data.multiIndex);
    this.setData({
      multiArray02,
      multiIndex02
    });

    for (var i = 0; i < datas.racquets_data.length; i++) {
      if (
        //multiArray02[0][multiIndex02[0]] == datas.racquets_data[i].brand &&
        multiArray02[1][multiIndex02[1]] == datas.racquets_data[i].name
      ) {
        var select02 = datas.racquets_data[i];
        break;
      } else {
        select02 = {};
      }

    }

    this.setData({
      selectright: select02,
    });

    console.log(multiArray02[0][multiIndex02[0]]);
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    for (var i = 0; i < datas.racquets_data.length; i++) {
      if (datas.racquets_data[i].brand == 'HEAD') {
        Head.push(datas.racquets_data[i].name);
      } else if (datas.racquets_data[i].brand == 'WILSON') {
        Wilson.push(datas.racquets_data[i].name);
      } else if (datas.racquets_data[i].brand == 'BABOLAT') {
        Babolat.push(datas.racquets_data[i].name);
      } else if (datas.racquets_data[i].brand == 'YONEX') {
        Yonex.push(datas.racquets_data[i].name);
      }
    }


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    wx.setNavigationBarTitle({
      title: '比较'
    })



  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})